home *** CD-ROM | disk | FTP | other *** search
- // **************************************************************
- // sort.cpp
- // Example program for Simple C++
- //
- // (c) 1999 Emmenjay Consulting Pty Ltd
- //
- // History
- // 04/06/99 MJS Initial Coding.
- //
- // **************************************************************
-
- #include <iostream>
- #include <cstring>
-
- const int LINELEN = 256;
- const int MAXLINES = 100;
-
- int ReadData( char data[MAXLINES][LINELEN] )
- {
- int NumLines = 0;
-
- while (NumLines<MAXLINES &&
- !std::cin.eof()) {
- std::cin.getline( data[NumLines++], LINELEN );
- }
- return NumLines;
- }
-
- void SortData( char data[MAXLINES][LINELEN], int NumLines )
- {
- for (int i=1; i<NumLines; i++) {
- char tmp[LINELEN];
- int j;
-
- strcpy( tmp, data[i] );
- j = i;
- while (j>0 && strcmp(data[j-1],tmp)>0) {
- strcpy( data[j], data[j-1] );
- j--;
- }
- strcpy( data[j], tmp );
- }
- }
-
- void WriteData( char data[MAXLINES][LINELEN], int NumLines )
- {
- for (int i=0; i<NumLines; i++)
- std::cout << data[i] << '\n';
- }
-
- int main( void )
- {
- char data[MAXLINES][LINELEN];
- int NumLines;
-
- NumLines = ReadData( data );
- SortData( data, NumLines );
- WriteData( data, NumLines );
-
- return 0;
- }
-